import csv
import unicodedata
import pandas as pd
from pyecharts.charts import *
from pyecharts import options as opts
def remove_hash_and_prefix(text):
    return text.lstrip('#').lstrip()
def count_elements(file_name):
    chinese_count = 0
    english_count = 0
    other_count = 0
    with open(file_name, 'r', encoding='utf-8') as f:
        reader = csv.reader(f)
        for row in reader:
            for item in row:
                item = remove_hash_and_prefix(item)
                if item:
                    if unicodedata.normalize('NFKC', item) != item:
                        chinese_count += 1
                    elif any(c.isalpha() for c in item):
                        english_count += 1
                    else:
                        other_count += 1
    return chinese_count, english_count, other_count
file_name = '../csv/tag_name1.csv'
chinese, english, other = count_elements(file_name)
print(f'中文元素个数: {chinese}')
print(f'英文元素个数: {english}')
print(f'其他元素个数: {other}')
def make_pie_4():

    chart = Pie(
        init_opts=opts.InitOpts(),
    )
    chart.add(
        '标签中中英日文出现数量及占比饼图',
        data_pair=[('中文标签出现数量', 622), ('英文标签出现数量', 2121), ('日文标签出现数量', 2184)],
    )
    chart.set_colors(['rgb(17, 0, 255)', 'rgb(255, 0, 0)', 'rgb(0,255,0)'])
    chart.set_global_opts(
        title_opts=opts.TitleOpts(
            title='标签中中英日文出现数量及占比饼图',
            pos_left="center",
            pos_bottom="0",
            title_textstyle_opts=opts.TextStyleOpts(color="black"),
        ),
        legend_opts=opts.LegendOpts(is_show=False),
    )
    chart.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
    chart.render('../html/标签中中英日文出现数量及占比饼图.html')
    return chart


if __name__ == "__main__":
    make_pie_4()
